package com.li.common.core.domain;

import com.li.common.core.enums.ResultCode;
import lombok.Getter;
import lombok.Setter;

/**
 * Description:
 * Date:2025-06-09
 * Time:14:47
 */
@Setter
@Getter
public class R<T> {
    private int code;//定义固定的状态码
    private String msg;//为code描述
    private T data;//请求的结果返回数据  泛型

    public static <T> R<T> ok() {
      return assembkeResult(null, ResultCode.SUCCESS);
    }

    public static <T> R<T> ok(T data) {
        return assembkeResult(data, ResultCode.SUCCESS);
    }

    public static <T> R<T> fail() {
        return assembkeResult(null, ResultCode.FAILED);
    }

    //指定错误码
    public static <T> R<T> fail(ResultCode resultCode) {
        return assembkeResult(null, resultCode);
    }

    public static <T> R<T> assembkeResult(T data,  ResultCode resultCode) {
        R<T> r = new R<>();
        r.setCode(resultCode.getCode());
        r.setMsg(resultCode.getMsg());
        r.setData(data);
        return r;
    }
}
